package com.atguigu.day15.string01.s2;

import org.junit.Test;

import java.util.Arrays;

public class StringMethod02 {
    @Test
    public void test01() {
        String s1 = "ABCDEF";
        boolean contains = s1.contains("CD6");
        System.out.println("contains = " + contains);//true

    }

    @Test
    public void test02() {
        String s1 = "ABCDEBF";
        //指定元素第一次出现的下标 乜有返回-1
        int indexOf = s1.indexOf("B6");
        System.out.println("indexOf = " + indexOf);
        ////指定元素最后一次出现的下标 乜有返回-1
        int lastIndexOf = s1.lastIndexOf("B1");
        System.out.println("lastIndexOf = " + lastIndexOf);
    }

    @Test
    public void test03() {
        String s1 = "ABCDEFG";
        boolean startsWith = s1.startsWith("AB");
        System.out.println("startsWith = " + startsWith);
        boolean endsWith = s1.endsWith("FG");
        System.out.println("endsWith = " + endsWith);
    }
    @Test
    public void test04(){
        String s1 = "你好世界";
        System.out.println("s1.charAt(0) = " + s1.charAt(0));
        System.out.println("s1.charAt(1) = " + s1.charAt(1));
    }
    @Test
    public void test05(){
        //todo 遍历字符串
        String s = "窗前明月光,疑是地上霜";

        for(int i = 0;i<s.length();i++){
            char e = s.charAt(i);
            System.out.println("e = " + e);

        }
    }
    @Test
    public void test06(){

        String s  ="ZBACD";
        //todo 将字符串-->字符数组
        char[] charArray = s.toCharArray();

        System.out.println("Arrays.toString(charArray) = " + Arrays.toString(charArray));
        for (char c : charArray) {
            System.out.println("c = " + c);
        }
        //排序
        Arrays.sort(charArray);
        System.out.println("Arrays.toString(charArray) = " + Arrays.toString(charArray));

        String newStr = new String(charArray);
        System.out.println("newStr = " + newStr);

    }
}
